package com.vhall.autotest.api_test.service.cloudwise;

import java.util.HashMap;
import java.util.Map;

import org.junit.Assert;

import com.alibaba.fastjson.JSONObject;
import com.vhall.autotest.api_test.common.Constant;
import com.vhall.autotest.api_test.common.ConstantCloudwise;
import com.vhall.autotest.api_test.common.Http;
import com.vhall.autotest.api_test.common.Http_new;
import com.vhall.autotest.api_test.common.HttpUtil;
import com.vhall.autotest.api_test.service.code.ICode;
import com.vhall.autotest.api_test.service.code.IWebinarCode;

public class CreeateAgent implements IWebinarCode{

	private static final String createAgentUrl = Constant.apiDomain + "/v2/agent/create.json?access_token="+	GetToken.getToken_success(ConstantCloudwise.grant_type, ConstantCloudwise.username, ConstantCloudwise.password, ConstantCloudwise.client_id, ConstantCloudwise.client_secret);
	/*
	 * 创建采集器
	 * 2016-5-25
	 */
	public static void createAgent_success(String name, String description, String agentType,String plugin_id) {
		Http http = new Http();
//	String createAgentUrl = Constant.apiDomain + "/v2/agent/create.json?access_token="+	GetToken.getToken_success(ConstantCloudwise.grant_type, ConstantCloudwise.username, ConstantCloudwise.password, ConstantCloudwise.client_id, ConstantCloudwise.client_secret)+"&name="+name+"&description="+description+"&agentType="+agentType;
		Map<String, String> param = new HashMap<String, String>();
//		param.put("access_token", access_token);
		param.put("name", name);
		param.put("description", description);
		param.put("agentType", agentType);
		param.put("plugin_id", plugin_id);
		System.out.println("param:" + param);
//		
//		Map<String, String> param1 = new HashMap<String, String>();
//		param1.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
//		System.out.println("param1:" + param1);
		try {
			Map<String, String> result = http.post(createAgentUrl, param,"x-www-form-urlencoded");
//			Map<String, String> result = new HttpUtil().requestByPostMethod(createAgentUrl, param);
			String statusCode = result.get("statusCode");
			String resultText = result.get("resultText");
			System.out.println("statusCode:" + statusCode);
			System.out.println("resultText:" + resultText);
			Assert.assertNotNull(statusCode);
			Assert.assertNotNull(resultText);
			Assert.assertTrue(String.valueOf(ICode.statusCodeSuccess).equals(statusCode));
			JSONObject obj = JSONObject.parseObject(resultText);
			System.out.println(obj);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		CreeateAgent.createAgent_success("snmpAgent1", "1", "linux","1000");
	}
	
	
	
}

